package com.bird.component.database

import com.baomidou.mybatisplus.core.mapper.BaseMapper
import com.baomidou.mybatisplus.core.metadata.IPage
import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper


inline fun <reified T : Any> BaseMapper<T>.queryOne(ktQueryWrapper: KtQueryWrapper<T>.() -> KtQueryWrapper<T>): T? {
    return this.selectOne(KtQueryWrapper(T::class.java).ktQueryWrapper())
}

inline fun <reified T : Any> BaseMapper<T>.queryList( ktQueryWrapper: KtQueryWrapper<T>.() -> KtQueryWrapper<T>): List<T> {
    return this.selectList(KtQueryWrapper(T::class.java).ktQueryWrapper())
}

inline fun <reified T : Any> BaseMapper<T>.queryPage(crossinline ktQueryWrapper: KtQueryWrapper<T>.() -> KtQueryWrapper<T>): (IPage<T>) -> IPage<T> {
    return { p -> this.selectPage(p, KtQueryWrapper(T::class.java).ktQueryWrapper()) }
}

inline fun <reified T : Any> BaseMapper<T>.delete(ktQueryWrapper: KtQueryWrapper<T>.() -> KtQueryWrapper<T>): Int {
    return this.delete(KtQueryWrapper(T::class.java).ktQueryWrapper())
}